package com.lxh.miniapp.utils;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.message.WxMaMessageRouter;
import com.lxh.miniapp.config.WxMiniAppConfiguration;
import org.apache.commons.lang3.StringUtils;

/**
 * created by lanxinghua@2dfire.com on 2020/2/23
 */
public class MiniAppUtils {
    public static WxMaService switchover(String appid){
        if (StringUtils.isBlank(appid)){
            throw new IllegalArgumentException("appId为空");
        }
        WxMaService wxMaService = WxMiniAppConfiguration.getMaService(appid);
        if (wxMaService == null) {
            throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置，请核实！", appid));
        }
        return wxMaService;
    }

    public static WxMaMessageRouter getRouter(String appid) {
        if (StringUtils.isBlank(appid)){
            throw new IllegalArgumentException("appId为空");
        }
        WxMaMessageRouter wxMaMessageRouter = WxMiniAppConfiguration.getRouter(appid);
        if (wxMaMessageRouter == null) {
            throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置，请核实！", appid));
        }
        return wxMaMessageRouter;
    }
}
